<?php
//error.php

//** getErrorMessage
//@$errorCode				This parameter refers to the individual error message
//@$options = 0				This parameter is an array containg an additional level of options for the error that correspond to the $errorCode
//return $error				The function returns an error string with the corresponding error message; the error is defaulted with "0: General Error."
//								if no specified error is given.
function getErrorMessage($errorCode, $options = 0){

	$error = "Error ";

	switch($errorCode){
		case 401: 	$error .= "401: Unauthorized User";	break;
		case 404: 	$error .= "404: File Not Found."; 	break;
		case 408: 	$error .= "408: Request Timeout."; 	break;
		case 300:	$error .= "300: You must be signed in to perform this action."; break;
		case 201:	$error .= "201: Missing user id."; break;
		case 9:		$error .= "9: Data is too short."; break;
		case 101:	$error .= "101: Recipie does not exist."; break;
		default:  	$error .= "0: General Error.";
	}
		
	return $error;
}

//** generateErrorPage
//@$errorNumber = 401		This is the error number that defaults with 401, an unauthorized user requesting the page.
//return					There is no default return. The function will generate a complete html5 page detailing the error to the user.
function generateErrorPage($errorNumber = 401){

	$error = getErrorMessage($errorNumber);

echo <<< EOT
	<!DOCTYPE HTML>
	<html>
	<head>
	<title>{$error}</title>
	<link rel="stylesheet" type="text/css" href="libraries/error.css" />
	<script type="text/javascript" src="libraries/error.js"></script>
	</head>
	
	<body>
	<div id="error">
		<h1>ERROR!</h1>
		<span class="ErrorMessage">{$error}</span>
		<br />
		<span class="Options">
			<a href="index.php">Home</a> |
			<a href="contact.php">Contact</a>
		</span>
	</div>
	</body>
	</html>
EOT;

die();
}

//** If user is not authorized to view this page directly
if(!isset($authorizedPage)) 
	generateErrorPage(401);

?>